package leetcode.primary;

import java.util.*;

public class T3 {
    int longest=0;
    Set a = new HashSet();
    int len;
    public int lengthOfLongestSubstring(String s) {
        len = s.length();
        int i=0;
        while(len-i>=longest){
            dfs(i,s);
            i++;
        }
        return longest;
    }
    public void dfs(int i,String s){
        if(i>=len || a.contains(s.charAt(i)) ){
            if(a.size()>longest){
                longest = a.size();
            }
            if(a.contains(" ")){
                longest-=1;
            }
            a.clear();
            return;
        }else{
            a.add(s.charAt(i));
            dfs(++i,s);
        }
    }
}
